/**
 * 应收账龄维护
 * @author liuw
 * @date 2019/09/06
 */
define(function () {

    var self,
        doc = document,
        app = win.app,
        layui = win.layui,
        element,
        table,
        table_gwax = {},
        cols = [[
            {field: 'ID', type: 'checkbox', title: '选择', fixed: 'left'},
            {field: "GWEF021_N1", title:"部门"},
            {field: "GWEF020_N1", title:"业务员"},
            {field: "GWAKL003", title:"客户名称",sort:true,search:'default',searchOpts:{icon:true}},
            {field: "GWEC002", title:"出货日期",sort:true},
            {field: "GWEFDOCDATE", title:"开票日期",sort:true},
            {field: "GWEF011", title:"价税合计"},
            {field: "DAY0_30", title:"0~30天"},
            {field: "DAY31_60", title:"31~60天"},
            {field: "DAY61_90", title:"61~90天"},
            {field: "DAY91_180", title:"91~180天"},
            {field: "DAY181_540", title:"181~540天"},
            {field: "DAY540UP", title:"540天以上"}
        ]],
        gweq024SettingAction
    ;

    var Gweq024 = app.Module.extend({
        init: function () {
            self = this;
            let searchArr = app.cloneJSON(cols[0]);
            self._super({
                _tag: 'gweq024',
                _searchs: [{
                    id: 'gweq024',
                    tableId: 'gweq024_table',
                    datas: searchArr.pushArray([
                        {field: 'GWEF020', title: '业务员', hide: true, search: 'default', searchOpts: {icon: true}},
                        {field: 'GWEF021', title: '销售部门', hide: true, search: 'default', searchOpts: {icon: true}},
                        {field: 'STANDARD', title: '计算基准', hide: true,
                            filterDatas: app.datas_('crm_gweq024_standard'),search:'default',searchOpts: {type: 'select'}},
                    ])
                }],
                _loadTplsFull: [
                    { dom: 'common_open_window', tpl: 'common/_open_window' }
                ]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gweq024_table'),
                    url: g_ctxPath + 'crm/gweq024/getListData',
                    exportsUrl: g_ctxPath + 'crm/gweq024/exportListData',
                    exportsName: '应收账龄数据',
                    title: '应收账龄信息表',
                    method: 'post',
                    id: 'gweq024_table',
                    size: _layuiConfig.ui_size,
                    autoSort: false, //禁用前端自动排序
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter', 'exports'],
                    height: 'full',
                    cols: cols,
                    loading: true,
                    page: true,
                    where: '',
                    done: function (res, curr, count) {

                    }
                });

                //监听事件
                table.on('toolbar(gwei023_table)', function (obj) {
                    switch (obj.event) {
                        case 'export':

                    }
                });


            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'gweq024_table', where: table_gwax});
        },

        _ready: function () {
            this._super({
                vue: [{
                    el: '#page',
                    data: '',
                    searchId: 'gweq024',
                    methods: {
                        handleIconClick: function (field) {
                            var vue = this;
                            if (field == 'GWAKL003') { //客户
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method:'q_gwak001',
                                            columnList: [
                                                {label:'客户编号',prop:'GWAK001', width: 150},
                                                {label:'客户简称',prop:'GWAKL003', width: 150},
                                                {label:'客户全称',prop:'GWAKL004', width: 150}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWAKL003 = data.GWAKL003;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择客户',
                                        area: ['600px', '430px']
                                    }
                                });
                            } else if (field == 'GWEF020') {//业务员开窗
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysuser_id',
                                            columnList: [{label: 'ID', prop: 'ID', width: '150'},
                                                {label: '名称', prop: 'NAME', width: '150'}]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWEF020 = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择业务员',
                                        area: ['600px', '465px']
                                    }
                                });
                            } else if (field == 'GWEF021') {//销售部门开窗
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysorg_id',
                                            columnList: [{label: '部门编号', prop: 'ID', width: '150'},
                                                {label: '部门名称', prop: 'NAME', width: '150'}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWEF021 = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择销售部门',
                                        area: ['600px', '470px']
                                    }
                                });
                            }
                        }
                    }
                }]
            });
            self.initTable();
        },
        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new Gweq024();

});